<input name="captcha" id="captcha" type="text" size="6" onfocus="showcaptcha();" value="点击显示" placeholder="验证码" class="f_gray" style="margin:10px 0 10px 0;"/>&nbsp;<img src="{DT_SKIN}image/loading.gif" title="验证码,看不清楚?请点击刷新&#10;字母不区分大小写" alt="" align="absmiddle" id="captchapng" onclick="reloadcaptcha();" style="display:none;cursor:pointer;"/><span id="ccaptcha"></span>
<script type="text/javascript">
function showcaptcha() {
	if(Dd('captchapng').style.display=='none') {
		Dd('captchapng').style.display='';
	}
	if(Dd('captchapng').src.indexOf('loading.gif') != -1) {
		Dd('captchapng').src='{DT_PATH}api/captcha.png.php?action=image';
	}
	if(Dd('captcha').value=='点击显示') {
		Dd('captcha').value='';
	}
	Dd('captcha').className = '';
}
function reloadcaptcha() {
	Dd('captchapng').src = '{DT_PATH}api/captcha.png.php?action=image&refresh='+Math.random();
	Dd('ccaptcha').innerHTML = '';
	Dd('captcha').value = '';
}
function checkcaptcha(s) {
	s = s.trim();
	var t = encodeURIComponent(s);
	if(t.indexOf('%E2%80%86') != -1) s = decodeURIComponent(t.replace(/%E2%80%86/g, ''));
	if(!is_captcha(s)) return;
	$.post(AJPath, 'action=captcha&captcha='+s,
		function(data) {
			if(data == '0') {
				Dd('ccaptcha').innerHTML = '&nbsp;&nbsp;<img src="{DT_SKIN}image/check_right.gif" align="absmiddle"/>';
				{if $DT_MOB[os] == 'ios'}
				Dd('captcha').value = s;
				{/if}
			} else {
				Dd('captcha').focus;
				Dd('ccaptcha').innerHTML = '&nbsp;&nbsp;<img src="{DT_SKIN}image/check_error.gif" align="absmiddle"/>';
			}
		}
	);
}
function is_captcha(v) {
	if(v == '点击显示') return false;
	if(v.match(/^[a-z0-9A-Z]{1,}$/)) {
		return v.match(/^[a-z0-9A-Z]{4,}$/);
	} else {
		return v.length > 1;
	}
}
$(function() {
	$('#captcha').bind('keyup blur', function() {
		checkcaptcha($('#captcha').val());
	});
});
</script>